/*
 *  CmnMacro.h
 *  VgoClient
 *
 *  Created by 21CN Vgo on 10-7-29.
 *  Copyright 2010 __MyCompanyName__. All rights reserved.
 *
 */

#import <objc/runtime.h>
#import "ARCMacros.h"

#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p)	\
{\
	if ((p) != nil) {\
		[(p) release];\
		(p) = nil;\
	}\
}
#endif

#ifndef SAFE_OPERATION
#define SAFE_OPERATION(p , operation)	\
{\
if ((p) != nil) {\
[(p) operation];\
}\
}
#endif

#ifndef LOG_RETAINCOUNT
#define LOG_RETAINCOUNT(p)	\
{\
	if ((p) != nil) {\
		NSLog(@"%s retainCount %d", #p, [(p) retainCount]);\
	}\
}
#endif

#ifndef SAFE_FORMAT_STRING
#define SAFE_FORMAT_STRING(p)	p ? p : @""
#endif

#ifndef RGB
#define RGB(r, g, b) \
	[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#endif

#ifndef RGBA
#define RGBA(r, g, b, a) \
	[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
#endif

#ifndef PROCESS_SUPERCLASS_METHOD
#define PROCESS_SUPERCLASS_METHOD(CLASS, SELECTOR, ...) \
({ \
	id ret = nil; \
	IMP method = class_getMethodImplementation([CLASS class], SELECTOR); \
	if (method) \
	{ \
		ret = (*method)(self, SELECTOR, ##__VA_ARGS__); \
	} \
	ret; \
})
#endif

#ifndef PROCESS_SUPERCLASS_METHOD_PARAMS
#define PROCESS_SUPERCLASS_METHOD_PARAMS(CLASS, SELECTOR, PARAMS...) \
({ \
	id ret = nil; \
	IMP method = class_getMethodImplementation([CLASS class], SELECTOR); \
	if (method) \
	{ \
		ret = (*method)(self, SELECTOR, PARAMS); \
	} \
	ret; \
})
#endif
